var numbers = [1,2,3,4,5,6];
numbers.forEach(function(item,index,arr){
    console.log(item,index,arr[index]);
    
})

var sum = 0;
numbers.forEach(function(value){
    sum+=value;
})

console.log(sum);


let filtResult =  numbers.filter(function(item,index,arr){
    return item>2;
})

console.log(filtResult);


//压缩稀疏数组
var sparse = [1,,,5];
var dense = sparse.filter(function(){
    return true;
})

console.log(dense);


let newResult = numbers.map(function(item,idnex,arr){
    return item*2;
})
console.log(newResult);


let sumss =  numbers.reduce(function(pre,cur,index,arr){
    return pre+cur;
})

console.log(sumss);

var max = numbers.reduce(function(pre,cur){
    return pre>cur?pre:cur;
})
console.log(max);

//总结
//全部都是;every,任意一个是some
//遍历每一项foreach,
//过滤获取数组目标数据集合：filter
//对数组中数据进行加工：map
//对数组多项数据进行多化一的整合，用reduce